package com.atguigu.lease.web.app.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.atguigu.lease.web.app.service.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {

     @Autowired
    Client client;

    @Override
    public void sendMsg(String phone, String code) {
        try {
             //构建发送短信的请求对象
            SendSmsRequest sendSmsRequest=new SendSmsRequest();
                    sendSmsRequest.setSignName("阿里云短信测试");
                    sendSmsRequest.setTemplateCode("SMS_154950909");
                    sendSmsRequest.setPhoneNumbers(phone);
                    sendSmsRequest.setTemplateParam("{\"code\":\""+code+"\"}");
            client.sendSms(sendSmsRequest);//发送短息
        } catch (Exception e) {
             e.printStackTrace();
        }
    }
}
